<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>店员查询</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../../bangnuo/admin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../../bangnuo/admin/style/admin.css" media="all">

</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">编号</label>
                    <div class="layui-input-block">
                        <input type="text" name="assistantUuid" placeholder="请输入" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">真实姓名</label>
                    <div class="layui-input-block">
                        <input type="text" name="assistantName" placeholder="请输入" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">登录名</label>
                    <div class="layui-input-block">
                        <input type="text" name="assistantUsername" placeholder="请输入" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">电话</label>
                    <div class="layui-input-block">
                        <input type="text" name="assistantPhone" placeholder="请输入" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">邮箱</label>
                    <div class="layui-input-block">
                        <input type="text" name="assistantEmail" placeholder="请输入" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">性别</label>
                    <div class="layui-input-block">
                        <select name="assistantSex">
                            <option value="">不限</option>
                            <option value="0">男</option>
                            <option value="1">女</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-user-front-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <div style="padding-bottom: 10px;">

                <button class="layui-btn layuiadmin-btn-useradmin" onclick="addassistant()">添加店员</button>
            </div>

            <table id="assistant-demo" lay-data="" data-value="{{}}" lay-filter="assistant-demo"></table>
            <script type="text/html" id="imgTpl">
                <img style="display: inline-block; width: 50%; height: 100%;" src={{ d.avatar }}>
            </script>
            <script type="text/html" id="table-useradmin-webuser">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i
                        class="layui-icon layui-icon-edit"></i>编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i
                        class="layui-icon layui-icon-delete"></i>删除</a>
            </script>
        </div>
    </div>
</div>
</body>
<script src="../../../bangnuo/admin/layui/layui.js"></script>
<script type="text/javascript" src="../../../bangnuo/admin/js/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
    function addassistant() {
        layui.use("table", function () {
            var table = layui.table;
            layer.open({
                type: 2,
                title: '新增店员',
                area: ['460px', '500px'],
                content: 'operation/add-assistant.html' //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
            });
        })
    }
</script>
<script type="text/javascript">
    layui.use(['util', 'table', 'form'], function () {
        var table = layui.table,
            form = layui.form;
        form.on('submit(LAY-user-front-search)', function (data) {
            var assistantEntity = {
                "assistantUsername": data.field.assistantUsername,
                "assistantName": data.field.assistantName,
                "assistantNumber": data.field.assistantNumber,
                "assistantEmail": data.field.assistantEmail,
                "assistantSex": data.field.assistantSex,
                "assistantUuid": data.field.assistantUuid,
                "assistantPhone": data.field.assistantPhone,
            }
            table.reload('admin-overloading', {
                url: '/assistantEntity/userQuery',
                where: assistantEntity,
                page:{
                    curr:1
                }
            });
            return false;
        });

        //第一个实例
        table.render({
            elem: '#assistant-demo',
            url: '/assistantEntity/userQuery',//数据接口
            method: "POST",
            toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
            contentType : "application/json",
            parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": 0, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.queryResult.total, //解析数据长度
                    "data": res.queryResult.list //解析数据列表
                };
            },
            page: true, //开启分页
            limit: 5,
            id: "admin-overloading",
            limits: [5, 10, 20, 50, 100],
            cols: [[ //表头
                {field: 'assistantUuid', title: '编号', width: 140, sort: true, fixed: 'left'},
                {field: 'assistantNumber', title: 'id', width: 140, sort: true, fixed: 'left'}
                , {field: 'assistantUsername', title: '登录名', width: 100}
                , {field: 'assistantName', title: '真实名字', width: 100, sort: true}
                , {field: 'assistantPhone', title: '电话', width: 120}
                , {field: 'assistantEmail', title: '邮箱', width: 160}
                , {field: 'assistantSex', title: '性别', width: 80, sort: true}
                , {field: 'assistantCreateTime', title: '创建时间',templet: '<div>{{ layui.util.toDateString(d.assistantCreateTime, "yyyy-MM-dd HH:mm:ss") }}</div>',
                width: 180, sort: true}
                , {fixed: 'right',align: 'center',title:'操作',toolbar: '#table-useradmin-webuser'}
                ]]
        });
        table.on('tool(assistant-demo)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
            if (layEvent === 'del') { //删除
                layer.confirm('真的删除行么', function (index) {
                    obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                    layer.close(index);
                    //向服务端发送删除指令
                    $.ajax({
                        type: "GET",
                        // url: "/adminEntity/delAdmin/" + data.adminUuid,
                        url: "/assistantEntity/delUser/" + data.assistantNumber,
                        async: true,
                        success: function (data) {
                            if (data.success == true) {
                                layer.msg("删除成功");
                            } else {
                                layer.msg("删除失败");
                            }
                        }
                    });
                });
            } else if (layEvent === 'edit') { //编辑
                //do something
                //同步更新缓存对应的值
                layer.open({
                    type: 2,
                    title: '修改店员',
                    area: ['400px', '500px'],
                    // content: 'users/edit-shop.html?id=' + data.adminUuid //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                    content: 'operation/edit-assistant.html?id=' + data.assistantNumber //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                });
                obj.update({
                    username: '123',
                    title: 'xxx'
                });
            } else if (layEvent === 'LAYTABLE_TIPS') {
                layer.alert('Hi，头部工具栏扩展的右侧图标。');
            }
        });
    });
</script>
</html>
